package com.kafka.consumer.consumer;

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class Consumer {

    // 采用监听的方式接收事件（消息、数据）
    @KafkaListener(topics = {"msg-reliability"}, groupId = "consumer1")
    public void receive(String message, Acknowledgment ack) {
        try {
            System.out.println("接收到的消息是：" + message);
            // 收到消息后，正常处理业务
            // ...
            // 业务处理完成，给kafka服务器确认
            ack.acknowledge();
        } catch (Exception e) {
            // 业务处理失败，不确认
        }
    }

}
